package tv.scolopender.adapter;

import java.util.ArrayList;

import tv.scolopender.R;
import tv.scolopender.model.Comment;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CommentArrayAdapter extends ArrayAdapter<Comment> {
	private final Context context;
	private final ArrayList<Comment> comments;

	public CommentArrayAdapter(Context context, int textViewResourceId,
			ArrayList<Comment> comments) {
		super(context, textViewResourceId, comments);
		this.context = context;
		this.comments = comments;
	}

	public CommentArrayAdapter(Context context, int textViewResourceId) {
		this(context, textViewResourceId, new ArrayList<Comment>());
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View rowView = inflater.inflate(R.layout.listitem_comment, parent,
				false);
		TextView nr = (TextView) rowView.findViewById(R.id.comment_nr);
		TextView text = (TextView) rowView.findViewById(R.id.comment_text);
		nr.setText("#" + (position + 1));
		text.setText(comments.get(position).getText());

		return rowView;
	}
}
